<template>
  <div class="header">
    <div class="collapse-btn">
      <i class="el-icon-menu" @click="collapseChange"></i>
    </div>
    <div class="logo">后台管理系统</div>
    <div class="header-right">
      <div class="header-user-con">
        <!-- 全屏 -->
        <div class="btn-fullscreen">
          <el-tooltip :content="fullscreen?`取消全屏`:'全屏'" placement="top">
            <i class="el-icon-rank" @click="handleFullScreen"></i>
          </el-tooltip>
        </div>
        <!-- 消息 -->
        <div class="btn-bell">
          <i class="el-icon-bell"></i>
        </div>
        <!-- 用户头像 -->
        <div class="user-avator"><img src="../../../static/img/img.jpg"></div>
        <!-- 用户下拉 -->

        <el-dropdown trigger="click">
          <span class="el-dropdown-link">
            {{username}}
            <i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>关于作者</el-dropdown-item>
            <el-dropdown-item>项目仓库</el-dropdown-item>
            <el-dropdown-item>退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>

      </div>
    </div>
  </div>
</template>
<script>
import bus from './bus'
export default {
  data () {
    return {
      username: 'admin',
      collapse: false,
      fullscreen: false
    }
  },
  methods: {
    collapseChange () {
      this.collapse = !this.collapse
      bus.$emit('collapse', this.collapse)
    },
    handleFullScreen () {
      let element = document.documentElement
      if (this.fullscreen) {
        if (document.exitFullscreen) {
          document.exitFullscreen()
        } else if (document.webkitCancelFullScreen) {
          document.webkitCancelFullScreen()
        } else if (document.mozCancelFullScreen) {
          document.mozCancelFullScreen()
        } else if (document.msExitFullscreen) {
          document.msExitFullscreen()
        }
      } else {
        if (element.requestFullscreen) {
          element.requestFullscreen()
        } else if (element.webkitRequestFullScreen) {
          element.webkitRequestFullScreen()
        } else if (element.mozRequestFullScreen) {
          element.mozRequestFullScreen()
        } else if (element.msRequestFullscreen) {
          // IE11
          element.msRequestFullscreen()
        }
      }
      this.fullscreen = !this.fullscreen
    }
  }
}
</script>

<style scoped>
.header {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: 70px;
  font-size: 22px;
  color: #fff;
  background-color: #242f42;
}
.collapse-btn {
  float: left;
  line-height: 70px;
  padding: 0 21px;
}
.header .logo {
  float: left;
  line-height: 70px;
}
.header-right {
  float: right;
  padding-right: 50px;
}
.header-user-con {
  display: flex;
  height: 70px;
  align-items: center;
}
.header-user-con .btn-fullscreen {
  transform: rotate(45deg);
  margin-right: 10px;
}
.header-user-con .user-avator {
  margin: 0 10px;
}
.user-avator img {
  display: block;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}
.el-dropdown {
  color: #fff;
  cursor: pointer;
}
</style>
